home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / DEMON / RISCOS2 / TCP_131S.ARC / c / iface < prev    next >
Text File  |  1993-12-22  |  2KB  |  57 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "global.h"
  4. #include "iface.h"
  5. #include "misc.h"
  6.  
  7. struct interface *if_lookup(char *name)
  8. {
  9.         register struct interface *iface;
  10.  
  11.         for(iface = ifaces; iface != NULLIF; iface = iface->next)
  12.                 if(strcmp(iface->name,name) == 0)
  13.                         break;
  14.         return iface;
  15. }
  16. /* Divert output packets from one interface to another. Useful for ARP
  17.  * and digipeat frames coming in from receive-only interfaces
  18.  */
  19. int doforward(int argc, char **argv)
  20. {
  21.         struct interface *iface,*iface1;
  22.         
  23.  
  24.         if(argc < 2){
  25.                 for(iface = ifaces; iface != NULLIF; iface = iface->next){
  26.                         if(iface->forw != NULLIF){
  27.                                 cwprintf(NULL, "%s -> %s\r\n",iface->name,iface->forw->name);
  28.                         }
  29.                 }
  30.                 return 0;
  31.         }
  32.         if((iface = if_lookup(argv[1])) == NULLIF){
  33.                 cwprintf(NULL, "Interface %s unknown\r\n",argv[1]);
  34.                 return 1;
  35.         }
  36.         if(argc < 3){
  37.                 if(iface->forw == NULLIF)
  38.                         cwprintf(NULL, "%s not forwarded\r\n",iface->name);
  39.                 else
  40.                         cwprintf(NULL, "%s -> %s\r\n",iface->name,iface->forw->name);
  41.                 return 0;
  42.         }
  43.         if((iface1 = if_lookup(argv[2])) == NULLIF){
  44.                 cwprintf(NULL, "Interface %s unknown\r\n",argv[2]);
  45.                 return 1;
  46.         }
  47.         if(iface1 == iface){
  48.                 /* Forward to self means "turn forwarding off" */
  49.                 iface->forw = NULLIF;
  50.         } else {
  51.                 if(iface1->output != iface->output)
  52.                         cwprintf(NULL, "Warning: Interfaces of different type\r\n");
  53.                 iface->forw = iface1;
  54.         }
  55.         return 0;
  56. }
  57.